#!/bin/sh

. scripts/functions

$bperl \
    -e "extract_resource('$conf/bacula-dir.conf', 'Client', '$HOST-fd')" \
    > $tmp/1

sed "s/$HOST-fd/test1-fd/" $tmp/1 >> $conf/bacula-dir.conf
sed "s/$HOST-fd/test2-fd/" $tmp/1 >> $conf/bacula-dir.conf
sed "s/$HOST-fd/test-rst-fd/" $tmp/1 >> $conf/bacula-dir.conf
sed "s/$HOST-fd/test-bkp-fd/" $tmp/1 >> $conf/bacula-dir.conf

cat <<EOF >> $conf/bacula-dir.conf
FileSet {
  Name = empty
}
Pool {
  Name = Test
  Pool Type = Backup
  Recycle = yes                       # Bacula can automatically recycle Volumes
  AutoPrune = yes                     # Prune expired volumes
  Volume Retention = 365d             # one year
}
Console {
  Name = restricted
  Password = xxx
  JobAcl    = *all*
  ClientAcl = test1-fd, test2-fd
  RestoreClientAcl = test-rst-fd
  BackupClientAcl = test-bkp-fd  
  PoolAcl   = *all*
  CatalogAcl  = *all*
  FileSetAcl  = *all*
  CommandAcl  = *all*
  StorageAcl  = *all*
  WhereAcl = $tmp/test-bkp-fd-restore, $tmp/test1-fd-restore, $tmp/test-rst-fd-restore-1, $tmp/test-rst-fd-restore-2
  DirectoryAcl = *all*
  UserIdAcl = *all*
}
Console {
  Name = restricted-bvfs1
  Password = xxx
  JobAcl    = *all*
  ClientAcl = test1-fd, test2-fd
  RestoreClientAcl = test-rst-fd
  PoolAcl   = *all*
  CatalogAcl  = *all*
  FileSetAcl  = *all*
  CommandAcl  = *all*
  StorageAcl  = *all*
  WhereAcl = $tmp/test-bkp-fd-restore, $tmp/test1-fd-restore, $tmp/test-rst-fd-restore-1, $tmp/test-rst-fd-restore-2
  DirectoryAcl = *all*
  UserIdAcl = *all*
}
Console {
  Name = restricted-bvfs2
  Password = xxx
  JobAcl    = *all*
  RestoreClientAcl = test-rst-fd
  PoolAcl   = *all*
  CatalogAcl  = *all*
  FileSetAcl  = *all*
  CommandAcl  = *all*
  StorageAcl  = *all*
  WhereAcl = $tmp/test-bkp-fd-restore, $tmp/test1-fd-restore, $tmp/test-rst-fd-restore-1, $tmp/test-rst-fd-restore-2
  DirectoryAcl = *all*
  UserIdAcl = *all*
}
Console {
  Name = restricted-job
  Password = xxx
  JobAcl    = $JobName
  ClientAcl = *all*
  PoolAcl   = *all*
  CatalogAcl  = *all*
  FileSetAcl  = *all*
  CommandAcl  = *all*
  StorageAcl  = *all*
  WhereAcl = *all*
  DirectoryAcl = *all*
  UserIdAcl = *all*
}
Console {
  Name = restricted-client
  Password = xxx
  JobAcl    = *all*
  ClientAcl = $HOST-fd
  PoolAcl   = *all*
  CatalogAcl  = *all*
  FileSetAcl  = *all*
  CommandAcl  = *all*
  StorageAcl  = *all*
  WhereAcl = *all*
  DirectoryAcl = *all*
  UserIdAcl = *all*
}
Console {
  Name = restricted-clients
  Password = xxx
  JobAcl    = *all*
  ClientAcl = $HOST-fd, test1-fd
  PoolAcl   = *all*
  CatalogAcl  = *all*
  FileSetAcl  = *all*
  CommandAcl  = *all*
  StorageAcl  = *all*
  WhereAcl = *all*
  DirectoryAcl = *all*
  UserIdAcl = *all*
}
Console {
  Name = restricted-pool
  Password = xxx
  JobAcl    = *all*
  ClientAcl = *all*
  PoolAcl   = Test
  CatalogAcl  = *all*
  FileSetAcl  = *all*
  CommandAcl  = *all*
  StorageAcl  = *all*
  WhereAcl = *all*
  DirectoryAcl = *all*
  UserIdAcl = *all*
}
Console {
  Name = restricted-fileset
  Password = xxx
  JobAcl    = *all*
  ClientAcl = *all*
  PoolAcl   = *all*
  CatalogAcl  = *all*
  FileSetAcl  = "Full Set"
  CommandAcl  = *all*
  StorageAcl  = *all*
  WhereAcl = *all*
  DirectoryAcl = *all*
  UserIdAcl = *all*
}
Console {
  Name = restricted-job-client
  Password = xxx
  JobAcl    = backup
  ClientAcl = test1-fd
  PoolAcl   = *all*
  CatalogAcl  = *all*
  FileSetAcl  = *all*
  CommandAcl  = *all*
  StorageAcl  = *all*
  WhereAcl = *all*
  DirectoryAcl = *all*
  UserIdAcl = *all*
}
EOF

cat <<EOF >> $tmp/bconsole.conf2
Console {
  Name = restricted
  Password = xxx
}
EOF

sed 's/Password.*/Password = xxx/' $conf/bconsole.conf >> $tmp/bconsole.conf2

for i in job pool client clients fileset bvfs1 bvfs2 job-client
do
    sed "s/restricted/restricted-$i/" $tmp/bconsole.conf2 > $tmp/bconsole.conf.$i
done
